/**
 * Copyright (c) 2003-2017 Ben Lau
 * All rights reserved.
 */
package thread;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * @author liubin
 *
 */
public class MultiThread {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// 获取java线程管理 MxBean
		ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();

		// 不需要获取同步的monitor和synchronizer信息，仅获取线程和线程堆栈信息
		ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(false, false);

		// 遍历线程信息，仅打印线程Id和线程名称信息
		for (ThreadInfo threadInfo : threadInfos) {
			System.out.println("[" + threadInfo.getThreadId() + "]" + threadInfo.getThreadName());
		}
	}

}
